package com.cxf.windex.rest;

import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.base.util.IdUtil;
import com.cxf.windex.biz.JsFollowBiz;
import com.cxf.windex.biz.JsTechBiz;
import com.cxf.windex.entity.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author chenxf
 * @date 3/20/2018
 * @description
 */
@Api(tags = {"小程序 - 关注接口"})
@Controller
@RequestMapping("/user/follow")
public class FollowController extends BaseRestController<JsFollowBiz, JsFollow> {


  @ApiOperation(value = "查询关注技师列表", notes = "查询关注技师列表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "limit", value = "记录数", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "offset", value = "页码", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String"),
  })
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  @ResponseBody
  public TableResultResponse<BResouces> list(@RequestParam(defaultValue = "10") int limit,
                                             @RequestParam(defaultValue = "1") int offset,
                                             String wxopenid) {
    List<BResouces> items = baseBiz.selectList(limit, offset, wxopenid);
    PageInfo<BResouces> pageInfo = new PageInfo<>(items);
    return new TableResultResponse<>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
            offset, limit,
            items);
  }

  @ApiOperation(value = "关注", notes = "关注福娃接口")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "resourcesId", value = "受赞福娃", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "type", value = "0取消 1关注", required = false, paramType = "query", dataType = "int")
  })
  @RequestMapping(value = "/like", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse edit(String resourcesId,String wxopenid ,@RequestParam(defaultValue = "1") int type) {
    return new ObjectRestResponse().rel(true).msg(baseBiz.follow(resourcesId,wxopenid,type));
  }


}
